<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>查看标签</el-breadcrumb-item>
      <el-breadcrumb-item>业务标签列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- gutter来设置行内列之间的距离 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="请输入想要查询的标签名"
            v-model="queryInfo.query"
            clearable
            @clear="LikeLabelList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="LikeLabelList"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
<!--          <el-button type="primary" @click="goAddPage">添加标签</el-button>-->
          <KtButton size="big" @click="goAddPage" label='添加标签' perms='admin' type="primary"/>
        </el-col>
      </el-row>
      <el-table :data="labelList" style="width: 100%">
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="operation" label="标签名称" width="135px"> </el-table-column>
        <el-table-column  label="标签类型" width="150px">业务信息
        </el-table-column>
<!--        <el-table-column prop="goods_weight" label="商品重量" width="80px">-->
<!--        </el-table-column>-->
<!--        <el-table-column label="创建时间" width="140px">-->
<!--          &lt;!&ndash; 使用全局时间过滤器将时间戳转为日期格式 &ndash;&gt;-->
<!--          <template slot-scope="scope">-->
<!--            {{ scope.row.add_time | dateFormat }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column label="操作" width="200px">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button-->
<!--              type="primary"-->
<!--              icon="el-icon-edit"-->
<!--              size="mini"-->
<!--              @click="editById(scope.row.id)"-->
<!--            ></el-button>-->
<!--            <el-button-->
<!--              type="danger"-->
<!--              icon="el-icon-delete"-->
<!--              size="mini"-->
<!--              @click="removeById(scope.row.id)"-->
<!--            ></el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="操作" width="360">
          <template slot-scope="scope">
            <KtButton size="mini" @click="editById(scope.row.id)" label='编辑' perms='admin' type="primary"/>
            &nbsp;
            <KtButton size="mini" @click="removeById(scope.row.id)" label='删除' perms='admin' type="danger"/>

          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 15, 25, 30]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next"
        :total="total"
        background
      >
<!--        layout="total, sizes, prev, pager, next, jumper"-->
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 请求参数对象
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      // 标签列表
      labelList: [],
      // 数据总条数
      total: 0,
    }
  },
  created() {
    this.getLabelList()
  },
  methods: {
    //获取标签信息
     getLabelList() {
       //基本信息
       this.getRequest('/operation/bypage?currentPage='+this.queryInfo.pagenum+'&size='+this.queryInfo.pagesize).then(resp=>{
         if (resp){
           this.labelList = resp.data;
           this.total = resp.total;
         }
       })
    },
    // //模糊查询标签信息
    LikeLabelList() {
      //业务信息
      this.getRequest('/operation/bypage?keyword='+this.queryInfo.query+'&currentPage='+this.queryInfo.pagenum+'&size='+this.queryInfo.pagesize).then(resp=>{
        console.log(resp)
        if (resp){
          this.labelList = resp.data;
          this.total = resp.total;
        }
      })
    },
    // 页容量发生改变时
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getLabelList()
    },
    // 页码发生变化
    handleCurrentChange(pageNum) {
      this.queryInfo.pagenum = pageNum
      this.getLabelList()
    },
    // 删除标签
    async removeById(id) {
      const result = await this.$confirm('确定要删除这个标签吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).catch((err) => err)
      if (result !== 'confirm') {
        return this.$message.info('已取消该删除操作！')
      } else {

        this.deleteRequest('/operation/'+id).then(resp=>{
          if(resp.code == 200){
            // return this.$message.info('删除成功！')
            this.$router.go(0)
          }else{
            return this.$message.info('删除失败！')
          }
        })
      }
    },
    // 添加按钮--到添加页面
    goAddPage() {
      this.$router.push('/label/add')
    },

    // 编辑按钮--存储商品id到原型，跳转到编辑页面
    editById(bid) {
      this.editLabelID.id = bid;
      this.editLabelType.type = "业务信息";
      this.$router.push('/label/edit')
    },
  },
}
</script>

<style lang="less" scoped>
</style>